import BaseCommand from "@/core/Frame/BaseClass/BaseCommand"

class RoamCommand extends BaseCommand {
  viewer: any

  constructor(params: any) {
    super()
    this.viewer = params.viewer
  }

  execute(option: any) {
    if (!option.checked) {
      document.onkeydown = null
      document.onkeyup = null
      return 
    }
    const globeControl = this.viewer.getGlobeControl()
    let initValuex = 0
    let initValuey = 0
    document.onkeydown = (e) => {
      document.getElementById('canvas').style.pointerEvents = 'none';
      globeControl.onTouchDown(initValuex, initValuey, 0, 0);

      if (e.key === 'ArrowUp') {
        globeControl.onTouchMove(initValuex, ++initValuey, 0, 0);
      }
      if (e.key === 'ArrowDown') {
        globeControl.onTouchMove(initValuex, --initValuey, 0, 0);
      }
      if (e.key === 'ArrowLeft') {
        globeControl.onTouchMove(++initValuex, initValuey, 0, 0);
      }
      if (e.key === 'ArrowRight') {
        globeControl.onTouchMove(--initValuex, initValuey, 0, 0);
      }
    }
    document.onkeyup = (e) => {
      document.getElementById('canvas').style.pointerEvents = 'auto';
      globeControl.onTouchUp(initValuex, initValuey, 0, 0);
    }
  }

  isEnable(option: any) {
    return true
  }
}

export default RoamCommand